<?php

/* -----------------------------------------------------------------
 * 	$Id: class.blog.php 1122 2014-06-25 20:28:08Z sbraeutig $
 * 	Copyright (c) 2011-2021 commerce:SEO by Webdesign Erfurt
 * 	http://www.commerce-seo.de
 * ------------------------------------------------------------------
 * 	based on:
 * 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 * 	(c) 2002-2003 osCommerce - www.oscommerce.com
 * 	(c) 2003     nextcommerce - www.nextcommerce.org
 * 	(c) 2005     xt:Commerce - www.xt-commerce.com
 * 	Released under the GNU General Public License
 * --------------------------------------------------------------- */

class blog_ORIGINAL {

    function blog_ORIGINAL($itemid = '') {
        
    }

    function array_sort($array, $on, $order = SORT_ASC) {
        $new_array = array();
        $sortable_array = array();
        if (count($array) > 0) {
            foreach ($array as $k => $v) {
                if (is_array($v)) {
                    foreach ($v as $k2 => $v2) {
                        if ($k2 == $on) {
                            $sortable_array[$k] = $v2;
                        }
                    }
                } else {
                    $sortable_array[$k] = $v;
                }
            }
            switch ($order) {
                case SORT_ASC:
                    asort($sortable_array);
                    break;
                case SORT_DESC:
                    arsort($sortable_array);
                    break;
            }
            foreach ($sortable_array as $k => $v) {
                $new_array[$k] = $array[$k];
            }
        }
        return $new_array;
    }

    function BlogCommentsCount($itemid = '') {
        $blogcomment = xtc_db_fetch_array(xtDBquery("SELECT COUNT(*) AS total 
									FROM blog_comment
									WHERE blog_id = '" . xtc_db_input($itemid) . "' 
									AND comment_status = '1' 
									AND text != '';"));
        return $blogcomment['total'];
    }

    function BlogCommentsRval($itemid = '') {
        $blogrval = xtc_db_fetch_array(xtDBquery("SELECT SUM(comment_rating) AS Rval, count(comment_rating) AS total
									FROM blog_comment
									WHERE blog_id = '" . xtc_db_input($itemid) . "' 
									AND comment_status = '1' 
									AND comment_rating != '0';"));
        if ($blogrval['total'] != '0') {
            $blogrevval = $blogrval['Rval'] / $blogrval['total'];
        } else {
            $blogrevval = '0';
        }
        return $blogrevval;
    }

    function getBlogComments($itemid = '') {
        require_once(DIR_FS_INC . 'xtc_date_short.inc.php');
        $data_reviews = array();
        $reviews_query = xtDBquery("SELECT *
								 FROM blog_comment
								 WHERE blog_id = '" . xtc_db_input($itemid) . "'
								 AND comment_status = '1'
								 ORDER BY id DESC;");

        if (xtc_db_num_rows($reviews_query) > 0) {
            $row = 0;
            $data_reviews = array();
            while ($reviews = xtc_db_fetch_array($reviews_query)) {
                $row++;
                $data_reviews[] = array('AUTHOR' => substr($reviews['name'], 0, strrpos($reviews['name'], " ") + 2) . '.',
                    'DATE' => xtc_date_short($reviews['date']),
                    'RATING' => xtc_image('templates/' . CURRENT_TEMPLATE . '/img/stars_' . $reviews['comment_rating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews['comment_rating'])),
                    'RATINGNUM' => $reviews['comment_rating'],
                    'TEXT' => $reviews['text']);
            }
        }
        return $data_reviews;
    }

    function getAntiSpam($spamid) {
        $antispam_query = xtc_db_fetch_array(xtc_db_query("SELECT id, answer FROM " . TABLE_CSEO_ANTISPAM . " WHERE language_id = '" . (int) $_SESSION['languages_id'] . "' AND id = '" . $spamid . "';"));
        return $antispam_query;
    }

}
